Skip to content

feat[venom]: add IRContext prefix + merge#4939

Open
mmsqe wants to merge 14 commits into
vyperlang:masterfrom
mmsqe:add_prefix
Open

feat[venom]: add IRContext prefix + merge#4939
mmsqe wants to merge 14 commits into
vyperlang:masterfrom
mmsqe:add_prefix

Conversation

@mmsqe

@mmsqe mmsqe commented Apr 25, 2026

Copy link
Copy Markdown

What I did

Add IRContext(prefix=...) + merge(*sources) so reusable code+data snippets can be authored with local names and spliced into a parent context without label collisions.

How I did it

Prefix auto-applied to label-emitting methods + str overloads, with prefixed_label(name) for refs that must survive merge. And merge validates first and raises on clash before mutating, clearing sources on success.

How to verify it

pytest tests/unit/compiler/venom/test_context_prefix.py covers prefix application and merge contract (moves+clears, raises on duplicate function / data-section labels, atomic-on-failure).

Commit message

feat[venom]: add IRContext prefix + merge

Description for the changelog

Added IRContext(prefix=...), prefixed_label(), and merge(*sources) for composing prefixed sub-contexts without label collisions

Closes #4938

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

mmsqe added 4 commits April 25, 2026 17:37
* reusable code+data snippets to avoid hand-invented unique label names
* add `IRContext(prefix=...)` so labels are namespaced automatically
* add `merge(*sources)` to combine prefixed sub-contexts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4018326459

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread vyper/venom/context.py
Comment on lines +123 to +127
function_labels = set(self.functions)
data_labels = {section.label for section in self.data_segment}

for src in sources:
for fn in src.functions.values():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate basic-block labels before merging contexts

IRContext.merge() only checks fn.name and data-section labels for collisions, but it does not validate labels inside each function’s basic blocks. Two sources can therefore pass validation (e.g. unique function names) yet still contain identical block labels generated from get_next_label() under the same prefix/empty prefix, and VenomCompiler will emit duplicate assembly symbols that fail in resolve_symbols with duplicate label. This makes merge non-atomic for a real collision class and can break compilation as soon as merged code is lowered to assembly.

Useful? React with 👍 / 👎.

@charles-cooper charles-cooper requested a review from harkal April 25, 2026 18:25
Comment thread vyper/venom/context.py Outdated
Comment thread vyper/venom/context.py
Comment thread vyper/venom/context.py Outdated
@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.97%. Comparing base (ecc24e2) to head (6c2bdfd).

Files with missing lines Patch % Lines
vyper/venom/builder.py 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4939      +/-   ##
==========================================
+ Coverage   91.94%   91.97%   +0.02%     
==========================================
  Files         186      186              
  Lines       27571    27611      +40     
  Branches     4818     4830      +12     
==========================================
+ Hits        25349    25394      +45     
+ Misses       1508     1503       -5     
  Partials      714      714              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IRContext prefix namespacing and atomic context merge

3 participants